library(dplyr)
library(ggplot2)
library(multiplot)
setwd("E:/5hmc_file/2_5hmc_yjp_bam/ASM/20201120")
normaldata=read.table("./normaldata.txt",head=T,sep="\t")
tumordata=read.table("./tumordata.txt",head=T,sep="\t")
normaldata$na=""
tumordata$na=""
p3=ggplot(normaldata,aes(y=DC.con.beta0,x=num))+scale_x_continuous(breaks = normaldata$num,labels = normaldata$na,position="top")+
  geom_point(aes(color=group),size=1.5)+geom_errorbar(aes(ymin=DC.con.beta0.lower,ymax=DC.con.beta0.upper,color=group),width=0.5)+labs(x="",y="DC con beta0")+
  geom_hline(yintercept = 0,color="red",linetype="dashed")+scale_color_manual(values = c('#708090','red'))+coord_flip()+theme_classic(base_size = 15)+
  theme(panel.grid.minor = element_blank(),panel.border = element_blank(),axis.line =element_line(size = 0.5))+theme(legend.position="none")

p4=ggplot(tumordata,aes(y=DC.case.beta0,x=num))+scale_x_continuous(breaks = tumordata$num,labels = tumordata$na)+
  geom_point(aes(color=group),size=1.5)+geom_errorbar(aes(ymin=DC.case.beta0.lower,ymax=DC.case.beta0.upper,color=group),width=0.5)+
  labs(x="",y="DC case beta0")+geom_hline(yintercept = 0,color="red",linetype="dashed")+scale_color_manual(values = c('#708090','red'))+theme_classic(base_size = 15)+
  theme(panel.grid.minor = element_blank(),panel.border = element_blank(),axis.line = element_line(size = 0.5))+coord_flip()+theme(legend.position="none")
layout <- matrix(c(1,2), nrow = 1)
multiplot(plotlist=list(p3,p4),layout=layout)

order=data.frame(unitID=normaldata$unitID,num=normaldata$num)
HC.case=read.table("HC.case.beta0.txt",head=T,sep="\t")
HC.con=read.table("HC.con.beta0.txt",head=T,sep="\t")

HC.case=merge(HC.case,order,by="unitID")
HC.con=merge(HC.con,order,by="unitID")
HC.case$na=""
HC.con$na=""

HC.case$group=ifelse(HC.case$HC.case.FDR<0.1,"sig","nosig")
HC.con$group=ifelse(HC.con$HC.con.FDR<0.1,"sig","nosig")

p5=ggplot(HC.con,aes(y=HC.con.beta0,x=num))+scale_x_continuous(breaks = HC.con$num,labels = HC.con$na,position="top")+
  geom_point(aes(color=group),size=1.5)+geom_errorbar(aes(ymin=HC.con.beta0.lower,ymax=HC.con.beta0.upper,color=group),width=0.5)+labs(x="",y="HC twin1 beta0")+
  geom_hline(yintercept = 0,color="red",linetype="dashed")+scale_color_manual(values = c('#708090','red'))+coord_flip()+theme_classic(base_size = 15)+
  theme(panel.grid.minor = element_blank(),panel.border = element_blank(),axis.line =element_line(size = 0.5))+theme(legend.position="none")

p6=ggplot(HC.case,aes(y=HC.case.beta0,x=num))+scale_x_continuous(breaks = HC.case$num,labels = HC.case$na)+
  geom_point(aes(color=group),size=1.5)+geom_errorbar(aes(ymin=HC.case.beta0.lower,ymax=HC.case.beta0.upper,color=group),width=0.5)+
  labs(x="",y="HC twin2 beta0")+geom_hline(yintercept = 0,color="red",linetype="dashed")+scale_color_manual(values = c('#708090','red'))+theme_classic(base_size = 15)+
  theme(panel.grid.minor = element_blank(),panel.border = element_blank(),axis.line = element_line(size = 0.5))+coord_flip()+theme(legend.position="none")

CC.case=read.table("CC.case.beta0.txt",head=T,sep="\t")
CC.con=read.table("CC.con.beta0.txt",head=T,sep="\t")

CC.case=merge(CC.case,order,by="unitID")
CC.con=merge(CC.con,order,by="unitID")
CC.case$na=""
CC.con$na=""

CC.case$group=ifelse(CC.case$CC.case.FDR<0.1,"sig","nosig")
CC.con$group=ifelse(CC.con$CC.con.FDR<0.1,"sig","nosig")

p7=ggplot(CC.con,aes(y=CC.con.beta0,x=num))+scale_x_continuous(breaks = CC.con$num,labels = CC.con$na,position="top")+
  geom_point(aes(color=group),size=1.5)+geom_errorbar(aes(ymin=CC.con.beta0.lower,ymax=CC.con.beta0.upper,color=group),width=0.5)+labs(x="",y="CC twin1 beta0")+
  geom_hline(yintercept = 0,color="red",linetype="dashed")+scale_color_manual(values = c('#708090','red'))+coord_flip()+theme_classic(base_size = 15)+
  theme(panel.grid.minor = element_blank(),panel.border = element_blank(),axis.line =element_line(size = 0.5))+theme(legend.position="none")

p8=ggplot(CC.case,aes(y=CC.case.beta0,x=num))+scale_x_continuous(breaks = CC.case$num,labels = CC.case$na)+
  geom_point(aes(color=group),size=1.5)+geom_errorbar(aes(ymin=CC.case.beta0.lower,ymax=CC.case.beta0.upper,color=group),width=0.5)+
  labs(x="",y="CC twin2 beta0")+geom_hline(yintercept = 0,color="red",linetype="dashed")+scale_color_manual(values = c('#708090','red'))+theme_classic(base_size = 15)+
  theme(panel.grid.minor = element_blank(),panel.border = element_blank(),axis.line = element_line(size = 0.5))+coord_flip()+theme(legend.position="none")

layout <- matrix(c(1,2,3,4,5,6), nrow = 1)
multiplot(plotlist=list(p3,p4,p7,p8,p5,p6),layout=layout)
